import { Ref, ref } from 'vue'

import { defineStore } from 'pinia'

import { useDict } from '@/api/uses'

import { store } from '@/store'

import IBaseObj from '#/index'

export const useDictStore = defineStore('dict', () => {
  const { dictData: _dictData, getDictData: _getDictData } = useDict()
  const dictData: Ref<IBaseObj> = ref(_dictData.value)

  const getDictData = async () => {
    if (Object.keys(dictData.value).length === 0) {
      await _getDictData()
      dictData.value = _dictData.value
    }
    return dictData.value
  }

  return {
    dictData,
    getDictData,
  }
})

export function useLocaleStoreWithOut() {
  return useDictStore(store)
}
